package biz.ezcom.spring.ioc.test;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import biz.ezcom.spring.ioc.controller.UserController;
import biz.ezcom.spring.ioc.dao.UserDao;
import biz.ezcom.spring.ioc.pojo.User;
import biz.ezcom.spring.ioc.service.UserService;


public class Client {
	public static ApplicationContext context = null;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		context = new ClassPathXmlApplicationContext("applicationContext-bean.xml");
	}
	
	@Test
	public void testComponent(){
		UserController userController = (UserController) context.getBean("userController");
		System.out.println("userController: " + userController);
		System.out.println("userController.getUserService():" + userController.getUserService());
		
		UserController userController2 = (UserController) context.getBean("userController");
		System.out.println("无@Scope: " + (userController == userController2));
		
		UserService userService = (UserService) context.getBean("userService");
		System.out.println("userService: " + userService);
		System.out.println("userService.getUserDao(): " + userService.getUserDao());
		UserService userService2 = (UserService) context.getBean("userService");
		System.out.println("@Scope: " + (userService == userService2));
		
		UserDao userDao = (UserDao) context.getBean("userDao");
		System.out.println("userDao: " + userDao);
		System.out.println("userDao.getUser():" + userDao.getUser());
		UserDao userDao2 = (UserDao) context.getBean("userDao");
		System.out.println("@Scope(\"singleton\"): " + (userDao == userDao2));
		
		User user = (User) context.getBean("user");
		System.out.println("user: " + user);
		User user2 = (User) context.getBean("user");
		System.out.println("@Scope(\"prototype\"): " + (user == user2));
		
		
	}
	
}
